﻿
Partial Class WebForm_ManageVolunteer_SearchPerson
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.BindDDLOrganization()
            RaiseEvent Loaded(Me, New EventArgs)

        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub

    Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
        Dim key As DataKey = Me.gv.DataKeys(e.RowIndex)
        Me.SelectedPersonID = key("PersonID")
        RaiseEvent Updating(Me, New EventArgs)
    End Sub
End Class

Partial Class WebForm_ManageVolunteer_SearchPerson
    Private Sub BindDDLOrganization()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select v.* ")
        sql.AppendFormat("from VOrganization v ")
        sql.AppendFormat("where v.OrganizationType = 'P' ")
        sql.AppendFormat("and v.Active='Y' ")

        ddlOrganizationID.DataTextField = "VOrganizationName"
        ddlOrganizationID.DataValueField = "VOrganizationID"
        'Dim sql As New MyOrganizationDataFilter

        'sql.AppendFormat("select UOrganizationID, OrganizationName = VOrganizationName from POrganization ")

        'Me.ddlOrganizationID.DataTextField = "OrganizationName"
        'Me.ddlOrganizationID.DataValueField = "UOrganizationID"
        Me.ddlOrganizationID.DataSource = dat.GetData(sql)
        Me.ddlOrganizationID.DataBind()
    End Sub

    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable
        sql.Length = 0
        sql.AppendFormat(" select p.* ")
        sql.AppendFormat(",vo.VOrganizationName as POrganizationName ")
        sql.AppendFormat("from Person p ")
        sql.AppendFormat("inner join VOrganization vo on p.VOrganizationID = vo.VOrganizationID ")
        ' sql.AppendFormat("inner join GetOrganizationTree('{0}') ot on p.VOrganizationID = ot.VOrganizationID ", Me.ddlOrganizationID.SelectedValue)
        If Me.ddlOrganizationID.SelectedValue <> "" Then
            sql.AppendFormat("where p.VOrganizationID='{0}' ", Me.ddlOrganizationID.SelectedValue)
        End If
        dt = dat.GetData(sql)
        Me.gv.DataSource = dt
        Me.gv.DataBind()
    End Sub

    Public Property SelectedPersonID() As String
        Get
            Return ViewState("SelectedPersonID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedPersonID") = value
        End Set
    End Property

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event Adding(ByVal source As Object, ByVal e As EventArgs)
    Public Event Updating(ByVal source As Object, ByVal e As EventArgs)
End Class